package com.hisysteTopet.hisystepet.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hisysteTopet.hisystepet.bean.IndentPet;
import com.hisysteTopet.hisystepet.bean.UserAndPet;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

@Mapper
public interface IndentToPetMapper extends BaseMapper<IndentPet> {

    // 根据用户名查询订单
    @Select("SELECT indent_pet.`indent_id`,indent_pet.`sum_money`,indent_pet.`data`,indent_pet.`address`,indent_pet.`payment`,indent_pet.`pet_num`,pet.`pet_name`\n" +
            "FROM indent_pet,pet" +
            " WHERE indent_pet.`pet_id` = pet.`pet_id` AND  username = #{username} ORDER BY  indent_pet.`data`  DESC")
    public List<IndentPet> selectAllIndentByUsername(String username) ;

    // 添加订单
    @Insert("INSERT INTO indent_pet(sum_money,`data`,address,username,pet_id,pet_num,pet_name)" +
            " VALUE(  #{sum_money}, #{data},  #{address},#{username},#{petId},#{petNum},#{petName})")
    public void insertIntend(Double sum_money, Date data, String address,String username,
                             Integer petId,Integer petNum,String petName);


    // 查询购买的宠物
    @Select("SELECT indent_pet.`username`,indent_pet.`indent_id`,pet.`pet_name`,pet.`pet_variety` FROM indent_pet,pet\n" +
            " WHERE pet.`pet_id` = indent_pet.`pet_id` AND username = #{username}")
    public List<UserAndPet> selectIntendToPet(String username);

    // 查询所有的购买宠物订单
    @Select("SELECT indent_pet.`address`,indent_pet.`data`,indent_pet.`indent_id`,indent_pet.`payment`," +
            "indent_pet.`pet_id`,indent_pet.`pet_num`,indent_pet.`sum_money`,pet.`pet_name`," +
            " FROM indent_pet LEFT JOIN pet ON indent_pet.`pet_id` = pet.`pet_id` " +
            " ORDER BY  indent_pet.`indent_id` DESC ")
    public List<IndentPet> selectAllIndent() ;

}
